//
//  DYPaywayCell.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/2/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit



class DYPaywayCell: SYBaseCell , UITableViewDelegate, UITableViewDataSource{
    
    var tableView: UITableView!
    var selectIndex: Int = 0
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5
        v.layer.masksToBounds = true
        return v
    }()

    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1D1D1D)
        v.font = 16.autoBoldFontSize()
        v.text = "支付方式"
        return v
    }()
    
    override func initViews() {
        
        setTableView()
        self.backgroundColor = Constant.bgViewColor
        
        contentView.addSubview(bgView)
        
        bgView.addSubview(nameLb)
        bgView.addSubview(tableView)
        
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.left.equalToSuperview()
            make.right.equalToSuperview()
        }
        nameLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(15.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(16.autoWidth())
        }
        tableView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(30.autoWidth())
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(126.autoWidth())
            make.bottom.equalToSuperview()
        }
    }

    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect(x: 0, y: NAV_HEIGHT, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-NAV_HEIGHT-BOTTOM_SAFE_HEIGHT), style:.plain)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.isScrollEnabled = false
        self.tableView!.register(DYPaywaySubCell.self, forCellReuseIdentifier: "Cell")
        self.contentView.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: DYPaywaySubCell? = tableView.dequeueReusableCell(withIdentifier: "Cell") as? DYPaywaySubCell
        if indexPath.row == 0 {
            cell?.pic.image = UIImage(named: "weixin")
            cell?.title.text = "微信支付"
            
        } else if indexPath.row == 1 {
            cell?.pic.image = UIImage(named: "zhifubao")
            cell?.title.text = "支付宝支付"
        } else {
            cell?.pic.image = UIImage(named: "yu_e")
            cell?.title.text = "余额支付"
        }
        cell?.selectionStyle = .none
        if selectIndex==indexPath.row {
            cell!.xuanze.isSelected = true
        } else {
            cell!.xuanze.isSelected = false
        }
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        self.selectIndex = indexPath.row
        self.tableView.reloadData()
        let currentvc = (self.currentVC as! DYZhifuViewController)
//        currentvc.params["payWay"] = "\(indexPath.row + 1)"
    }
}




class DYPaywaySubCell: SYBaseCell {
    


    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 15.autoFontSize()
        
        
        return v
    }()
    
    let content: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0xA6A6A6)
        v.font = 13.autoFontSize()
        
        
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        
        return v
    }()

    let xuanze: UIButton = {
        let v: UIButton  = UIButton()
        v.setImage(UIImage(named: "zhifu_un"), for: .normal)
        v.setImage(UIImage(named: "zhifu_select"), for: .selected)
        v.isUserInteractionEnabled = false
        return v
    }()

    override func initViews() {
        
        
        contentView.addSubview(lineView)
        contentView.addSubview(title)
        contentView.addSubview(content)
        contentView.addSubview(pic)
        contentView.addSubview(xuanze)
        
        lineView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(0.5.autoWidth())
            make.bottom.equalToSuperview()
        }
        pic.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(24.autoWidth())
        }
        title.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(45)
            make.centerY.equalToSuperview()
            make.height.equalTo(18.autoWidth())
        }
        content.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(116)
            make.centerY.equalToSuperview()
            make.height.equalTo(15.autoWidth())
        }
        xuanze.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(19.autoWidth())
        }
    }

}




class DYPayPriceCell: SYBaseCell {
    


    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor.white
        v.font = 13.autoFontSize()
        v.text = "舒适商务标间 | 双床 | 有早餐 |1-18入住1晚"
        return v
    }()
    
    let content: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor.white
        v.font = 17.autoFontSize()
        v.text = "￥358.00"
        
        return v
    }()

    let imgView: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "pay_bg")
        return v
    }()

    override func initViews() {
        
        self.backgroundColor = .clear
        contentView.addSubview(imgView)
        contentView.addSubview(title)
        contentView.addSubview(content)
        
        
        imgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(150.autoWidth())
            make.bottom.equalToSuperview().offset(-3.5.autoWidth())
            make.top.equalToSuperview().offset(10.autoWidth())
        }
      
        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(85)
            make.centerX.equalToSuperview()
            make.height.equalTo(19.autoWidth())
        }
        content.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(45)
            make.centerX.equalToSuperview()
            make.height.equalTo(14.autoWidth())
        }
     
    }

}
